package com.liuyuan.controller;
import com.liuyuan.pojo.User;
import com.liuyuan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
@RequestMapping("/thyme")
public class ThymeleafController {
    @Autowired
    private UserService userService;
    @RequestMapping("/demo1")
    public String demo1(){
        System.out.println("demo1");
        return "demo1";
    }
    @RequestMapping("/demo2")
    public String demo2(Model model){
        System.out.println("demo2");
        model.addAttribute("thyme","传递thyme");
        return "demo2";

    }
    @RequestMapping("/demo3")
    public String demo3(HttpServletRequest request,Model model){
        String name="zhangsan";
        int age =18;
        String content ="<a href='http://www.baidu.com'>百度</a>";
        model.addAttribute("name",name);
        model.addAttribute("age",age);
        request.setAttribute("content",content);
        return "demo3";
    }

    @RequestMapping("/demo4")
    public String demo4(Model model,int id){
        User user = userService.getUserById(id);
        model.addAttribute("user",user);
        return "demo4";
    }
  @RequestMapping("/demo5")
    public String demo5(HttpServletRequest request){
      List<User> userList =userService.getAllUser();
      request.setAttribute("userList",userList);
      return "demo5";
  }


}